#define _CRT_SECURE_NO_WARNINGS 1
class Solution
{
public:
    void rotate(vector<int>& nums, int k)
    {
        int n = nums.size();
        vector<int> nums1(n);
        for (int i = 0; i < n; i++)
        {
            nums1[(i + k) % n] = nums[i];
        }
        nums.assign(nums1.begin(), nums1.end());

    }
};
class Solution
{
public:
    int majorityElement(vector<int>& nums)
    {
        int n = nums.size();
        unordered_map<int, int> hash;
        int s = 0, cnt = 0;
        for (int ch : nums)
        {
            hash[ch]++;
            if (hash[ch] > s)
            {
                s = hash[ch];
                cnt = ch;
            }
        }
        return cnt;
    }
};

class Solution {
public:
    int removeElement(vector<int>& nums, int val) {
        int left = 0;
        int right = nums.size() - 1;
        while (left <= right) {
            if (nums[left] == val) {
                nums[left] = nums[right];
                right--;
            }
            else {
                left++;
            }
        }
        nums.resize(left);
        return left;

    }
};
class Solution 
{
public:
    void merge(vector<int>& nums1, int m, vector<int>& nums2, int n) 
    {
        int i = nums1.size() - 1;
        m--,n--;
        while(n >= 0)
        {
            while(m >= 0 && nums1[m] > nums2[n])
            {
                swap(nums1[i--], nums1[m--]);
            }
            swap(nums1[i--], nums2[n--]);
        }
    }
};

class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        int n = nums.size();
        if (n <= 2) return n;
        int slow = 2, fast = 2;
        while (fast < n)
        {
            if (nums[slow - 2] != nums[fast])
                nums[slow++] = nums[fast];
            fast++;
        }
        return slow;
    }
};
class Solution {
public:
    int removeDuplicates(vector<int>& nums) {
        int n = nums.size();
        if (n == 0) return 0;
        int fast = 1, slow = 1;
        while (fast < n)
        {
            if (nums[fast] != nums[fast - 1])
                nums[slow++] = nums[fast];
            fast++;
        }
        nums.resize(slow);
        return slow;
    }
};